import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'layout',
      component: ()=>import('@/views/layout/index.vue'),
      children:[
        {
          path:'',
          name: 'home',
          component: () => import('@/views/home/index.vue')
        },
        {
          path: 'category/:id',
          name: 'category',
          component: () => import('@/views/category/index.vue'),
        },
        {
          path: 'category/sub/:id',
          name: 'subcategory',
          component: () => import('@/views/subcategory/index.vue'),
        },
        {
          path: 'detail/:id',
          name: 'detail',
          component: () => import("@/views/detail/index.vue")
        },
        {
          path:'cartList',
          name:'cartList',
          component: () => import('@/views/cartList/index.vue')
        },
        {
          path:'checkout',
          name:'checkout',
          component: () => import('@/views/checkout/index.vue')
        },{
          path:'pay',
          name:'pay',
          component: () => import('@/views/pay/index.vue')
        },
        {
          path:'paycallback',
          name:'paycallback',
          component:() => import('@/views/pay/PayBack.vue')
        },
        {
          path:'member',
          name:'member',
          component: () => import('@/views/member/index.vue'),
          redirect:'member/user',
          children:[
            {
              path:'user',
              name:'userInfo',
              component: () => import('@/views/member/components/userInfo.vue')
            },
            {
              path:'order',
              name:'order',
              component: () => import('@/views/member/components/UserOrder.vue')
            },
          ]
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/index.vue')
    }
  ],
  // 路由跳转时，滚动条滚动到顶部
  scrollBehavior() {
    return { top: 0 }
  }
})

export default router
